package com.wfms.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.wfms.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/12/25.
 */
@RestController
@RequestMapping("/hystrix")
public class HystrixController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/getById")
    @HystrixCommand(fallbackMethod = "failRequets")
    public User getById(){
        ResponseEntity<User> responseEntity= restTemplate.getForEntity("http://eurekaClient/eureka/user/{1}", User.class,1);
        return responseEntity.getBody();
    }

    public User failRequets(){
        return new User("error",11);
    }

}
